package com.game.user;

import java.nio.ByteBuffer;



/***
 * 聊天转发
 * @author chenlei
 *
 */
public class userTalk implements Cloneable{
	
	
	public void Talk(User user,byte[] pack){
		int type=pack[1];
		switch(type){
			case 1:
				int offset=2;
				byte length = pack[offset];
				String name = new String(pack,offset,length);   //接受私聊角色名称
				offset+=length;
				length = pack[offset];
				offset++;
				String content = new String(pack,offset,length);   //内容
				System.out.println("私聊包......");
						
				////转发给接收方
				ByteBuffer tempData = ByteBuffer.allocate(100);
				tempData.put(Byte.MIN_VALUE);
				tempData.put((byte)3);
				tempData.put((byte)2);	
				tempData.put((byte)user.getName().getBytes().length);
				tempData.put(user.getName().getBytes());
				tempData.put((byte)length);
				tempData.put(content.getBytes());
				tempData.put(0, (byte) (tempData.position()-130));
				tempData.flip();
				User userBean=User.getUserByName(name);
				userBean.putdata(tempData);
				break;
				default :
					System.out.println("没有可处理的数据类型");
		}
	}
	
	@Override
	public userTalk clone(){
		userTalk t=null;
		try {
			 t=(userTalk) super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return t;
	}
}
